package com.itheima.jdbc.数据库MYSQL.JDBC连接;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo1 {
    public static void main(String[] args) {
        Connection connection=null;
        Statement statement=null;
        //注册驱动
        try {
            Class.forName("com.mysql.jdbc.Driver");
            //获取连接对象
            //定义sql
            String sql="update account set balance=1500 where id=3";
            //获取执行sql对象
            statement=connection.createStatement();
            //执行sql
            int i = statement.executeUpdate(sql);
            //处理结果
            System.out.println(i);
            if(i>0){
                System.out.println("修改成功");
            }else{
                System.out.println("修改失败");
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            //释放资源
            if(statement!=null){
                try {
                    statement.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if(connection!=null){
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
